package com.xing.adapter;

import java.util.List;

import com.xing.model.HsdModelSurvey;
import com.xing.questionnairesurvey.R;
import com.xing.util.ViewUtil;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ManageListNativeAdapter extends BaseAdapter {

	
	private LayoutInflater inflater;
	private List<HsdModelSurvey> mList;
	private Context mContext;
	private FragmentManager fragmentManager;
	
	public ManageListNativeAdapter(Context context,List<HsdModelSurvey> list,FragmentManager frmg){
		this.inflater = LayoutInflater.from(context);
		this.mList = list;
		this.mContext = context;
		this.fragmentManager = frmg;
	}
	

	public int getCount() {
		// TODO Auto-generated method stub
		if(mList != null){
			return mList.size();
		}
		return 0;
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		if(mList != null){
			return mList.get(arg0);
		}
		return null;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		if(mList != null){
			return position;
		}
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		HsdModelSurvey object  = mList.get(position);
		System.out.println("object.getStatus()----"+object.getStatus());;
		if(convertView == null){
			convertView = inflater.inflate(R.layout.manage_native_list_item, null);
		}
			
		ImageView statusImageView = (ImageView) convertView.findViewById(R.id.status_imgv);
		TextView questionnaireNameTextView = (TextView) convertView.findViewById(R.id.questionnaire_name);
		questionnaireNameTextView.setText(String.valueOf(object.getName()));
		
		/**
		 * 问卷状态
		 * 1 not download
		 * 2:has downloaded
		 * 3:out of date
		 * 4:has deleted
		 */
		if (object.getStatus() == 3) {
			statusImageView.setImageResource(R.drawable.out_of_date_imgv);
		}else if(object.getStatus() == 4) {
			statusImageView.setImageResource(R.drawable.has_deleted_imgv);
		}else if (object.getStatus() == 2) {
			statusImageView.setImageResource(R.drawable.has_downloaded_imgv);
		}
		convertView.findViewById(R.id.delete_btn).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				ViewUtil.showToast(mContext, "暂时不支持删除");
				// TODO Auto-generated method stub
//				FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
//				fragmentTransaction.hide(fragmentManager.findFragmentByTag(FragmentNameFlagList.SURVEY));
//				SurveySecondFragment surveySecondFragment = new SurveySecondFragment(); 
//				fragmentTransaction.add(R.id.fragmentRoot, surveySecondFragment, FragmentNameFlagList.SURVEY_SECOND_FRAGMENT);
//				fragmentTransaction.addToBackStack(FragmentNameFlagList.SURVEY_SECOND_FRAGMENT);
//				fragmentTransaction.commit();
			}
		});
		
		return convertView;
	}


}
